package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import Model.DeviationNotes;

public class DeviationNotesDB {
	
	public static void update(String ValURL, String ValName)
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		String select = "UPDATE deviationnotes SET DNoteURL = ? WHERE DNoteName = ?";
		
		try
		{
			stmt = con.prepareStatement(select);
			stmt.setString(1, ValURL);
			stmt.setString(2, ValName);
			stmt.executeUpdate();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}
	}
	public static ArrayList <DeviationNotes> GetManual()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM deviationnotes ORDER BY DNoteName";

		ArrayList<DeviationNotes> notesarry = new ArrayList<DeviationNotes>();
		DeviationNotes notes = null;

		try
		{
			stmt = con.prepareStatement(select);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				notes = new DeviationNotes();
				notes.setName(rs.getString("DNoteName"));
				notes.setId(rs.getInt("idDeviationNotes"));

				notesarry.add(notes);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			notes = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return notesarry;
	}
}
